package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionDetailVO;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author yb0os1
 * @since 2024-12-21
 */
@Api(tags = "用户端提问相关接口")
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {
    private final IInteractionQuestionService interactionQuestionService;
    @ApiOperation("新增互动问题")
    @PostMapping
    public void addQuestion(@RequestBody @Validated QuestionFormDTO questionDTO){
        interactionQuestionService.addQuestion(questionDTO);
    }

    @ApiOperation("编辑互动问题")
    @PutMapping("/{id}")
    public void editQuestion(@PathVariable Long id, @RequestBody QuestionFormDTO questionDTO){
        interactionQuestionService.editQuestion(id,questionDTO);
    }

    @ApiOperation("用户端分页查询")
    @GetMapping("/page")
    public PageDTO<QuestionVO> queryUserQuestionPage(QuestionPageQuery page){
        return interactionQuestionService.queryUserQuestionPage(page);
    }

    @ApiOperation("用户根据id查询问题详细")
    @GetMapping("/{id}")
    public QuestionDetailVO queryQuestionById(@PathVariable Long id){
        return interactionQuestionService.getQuestionDetail(id);
    }

    @ApiOperation("删除我的问题")
    @DeleteMapping("/{id}")
    public void deleteMyQuestion(@PathVariable Long id){
        interactionQuestionService.deleteMyQuestion(id);
    }
}
